#coding=utf-8

import os
import sys
import platform

OS_NAME = platform.system();
LIB_DIR=os.environ['LIB_DIR'];
BIN_DIR=os.environ['BIN_DIR'];

env=DefaultEnvironment().Clone()
SOURCES=Glob('usb_camera/*.c')+Glob('*.c')+Glob('usb_camera/devices/usb_camera_devices.c')

DEVICE_TYPE = 'v4l2'
# v4l 协议已经是被抛弃的协议，可能会出现系统不兼容的问题，不建议使用。
#DEVICE_TYPE = 'v4l'

if OS_NAME == 'Windows' and os.environ['TOOLS_NAME'] == '':
  SOURCES += Glob('usb_camera/devices/usb_camera_window_device.cpp')
elif OS_NAME == 'Linux':
  if DEVICE_TYPE == 'v4l2':
    SOURCES += Glob('usb_camera/devices/usb_camera_linux_device_v4l2.cpp')
  elif DEVICE_TYPE == 'v4l':
    SOURCES += Glob('usb_camera/devices/usb_camera_linux_device_v4l.cpp')

EXPORT_DEF=''
if OS_NAME == 'Windows' and os.environ['TOOLS_NAME'] == '':
  EXPORT_DEF = ' /DEF:"src/usb_camera.def" '

if 'BUILD_SHARED' in os.environ and os.environ['BUILD_SHARED'] == 'True':
  LIBS=['awtk'];
  LINKFLAGS=env['LINKFLAGS'] + EXPORT_DEF 
  env.SharedLibrary(os.path.join(BIN_DIR, 'usb_camera'), SOURCES, LIBS=LIBS, LINKFLAGS=LINKFLAGS);
else:
  env.Library(os.path.join(LIB_DIR, 'usb_camera'), SOURCES);

